<template>
<view>
	<view class="wrap">
		<u-back-top :scroll-top="scrollTop"></u-back-top>
	</view>
	<u-loading-icon text="加载中..." textSize="18" :show="jiazai" ></u-loading-icon>
	
	<!-- 帖子 -->
	<view v-if="tiezijiazai" class="d-kuan ">
		
		<!-- 标题 -->
		<view v-if="tiezineirong.title" class="entry-title d-waikuang-10">{{tiezineirong.title}}</view>
		<!-- 头像 -->
		<view class="d-waikuang-10 d-buhuanhang">
			<!--头像-->
			<view class="d-gaokuang-40 d-kuanggao-40 d-yuanjiao-40 d-box"  >
				
				<image src="/static/assets/images/avatar.png" mode="aspectFill" class="d-img-40 d-yuanjiao-50"></image>
				
			</view>
			<view class="d-kuan d-zuo-10" >
				<view class="d-wenzi-14 d-jiacu">使用帮助</view>
				<view class="d-wenzi-14 d-wenzi-yanse-hui">阅读：{{tiezineirong.hits}}</view>
			</view>
			<view class="d-kuan-80 d-neirong-you" >
				<view class="d-kuan-50 d-beijing-hui-f6 d-neikuang-zuoyou-2-shangxia-4 d-wenzi-12 d-yuanjiao-50 d-neirong-juzhong " >{{tiezineirong.catname}}</view>
			</view>
		</view>
		<!-- 内容 -->
		<view class="d-waikuang-10">
			<jyf-parser :html="tiezineirong.content"   :use-cache="true"></jyf-parser>
		</view>
		<u-gap height="50" bgColor="#ffffff"></u-gap>

	<view>

	<view class="ditail-copyright">
		<block data-type="template" data-is="tempCopyright" data-attr="webSiteName:webSiteName,domain:domain">
			<view> {{webSiteName}} </view>
		</block>
	</view>

</view>
</view>
</view>
</template>

<script>

import config from "../../utils/config";

var Api = require("../../utils/api.js");
var util = require("../../utils/util.js");

var wxApi = require("../../utils/wxApi.js");
var wxRequest = require("../../utils/wxRequest.js");
const innerAudioContext = uni.createInnerAudioContext();
let isFocusing = false;
const pageCount = config.getPageCount;
var webSiteName = config.getWebsiteName;
var domain = config.getDomain;
var defaultskin = config.getskin;
let rewardedVideoAd = null;


export default {
  data() {
    return {
      //title: '文章内容',
      webSiteName: webSiteName,
      isLoading: false,
	  tiezineirong: {},
	  jiazai:true,
	  tiezijiazai:false,
	  pinglun: [],
	  pingluntongji: 0,
	  tieids: '',
	  "reqFlag": false ,// 请求标志，防止重复操作，true表示请求中
	  member:'',
	  userInfo: '',
	  memberuid: '',
	  scrollTop: 0,
	  bgColor: '#ffffff',
	  keycode:'',

    };
  },

  components: {

  },
  props: {},
  onPageScroll(e) {
  	this.scrollTop = e.scrollTop;
	//console.log("scrollTop",e.scrollTop);
  },
  onShow: function (options) {
    var that = this;
    var skin = uni.getStorageSync('skin');

    if (skin != '') {
      that.setData({
        skin: skin
      });
    }
	
  },
  onLoad: function (options) {
	  
    var duixin = this;
	duixin.tieids = options.id;

	//duixin.gundong();
    var skin = uni.getStorageSync('skin');
	//判断用户是否登录
	var userInfo = uni.getStorageSync('userInfo');
	var keycode = uni.getStorageSync('keycode');
	duixin.keycode = keycode;
	//console.log("options",options);
	if (userInfo) {
		var member = uni.getStorageSync('member');
		var memberuid = uni.getStorageSync('memberuid');
		duixin.member = member;
		duixin.userInfo = userInfo;
		duixin.memberuid = memberuid;
		duixin.uid = memberuid;
	}
	duixin.getTieziid();
	
    if (skin != '') {
      duixin.setData({
        skin: skin
      });
    }
	
	
  },
  onShow: function () {
  	  
  },
  onUnload: function () {},
  //分享到个人朋友圈
  onShareAppMessage: function (res) {
    return {
      title: this.tiezineirong.title,
      path: 'pages/bangzhu/tiezi?id=' + this.tiezineirong.id,
      //imageUrl: this.tiezineirong.post_full_image,
      success: function (res) {
        // 转发成功
        //console.log(res);
      },
      fail: function (res) {
        //console.log(res); // 转发失败
      }
    };
  },
  //分享到朋友圈
  onShareTimeline: function (res) {
  	  return {
  	    title: this.tiezineirong.title,
  	    path: 'pages/bangzhu/tiezi?id=' + this.tiezineirong.id,
		imageUrl: this.tiezineirong.title,
  	    success: function (res) {// 转发成功
  	    },
  	    fail: function (res) {// 转发失败
  	    }
  	  };
  },
  methods: {
    BackPage() {
      uni.navigateBack({
        delta: 1
      });
    },
	fanhui() {
		const pages = getCurrentPages();  //判断跳转了多少页
		if (pages.length === 2) {  
			uni.navigateBack({
				delta: 1
			});
		} else if (pages.length === 1) { //如果没有上一页返回首页
			uni.switchTab({
				url: '/pages/index/index',
			})
		} else {
			uni.navigateBack({
				delta: 1
			});
		}
		
	},

    toHome() {
      uni.reLaunch({
        url: '/pages/index/index'
      });
    },

    copyLink: function (url) {
      uni.setClipboardData({
        data: url,
        success: function (res) {
          uni.getClipboardData({
            success: function (res) {
              uni.showToast({
                title: '链接已复制',
                image: "/static/images/uploads/link.png",
                duration: 2000
              });
            }
          });
        }
      });
    },
    copyText: function (e) {
      console.log(e);
      uni.setClipboardData({
        data: e.currentTarget.dataset.text,
        success: function (res) {
          uni.getClipboardData({
            success: function (res) {
              uni.showToast({
                title: '复制成功'
              });
            }
          });
        }
      });
    },
    gourl: function () {
      var url = '../webpage/webpage';
      uni.navigateTo({
        url: url + '?url=' + e.currentTarget.dataset.text
      });
    },
    goHome: function () {
      uni.switchTab({
        url: '../index/index'
      });
    },

	//获取帖子内容
	getTieziid() {
		var duixin = this;

		var getBangzhushowRequest = wxRequest.getRequest(Api.getBangzhushow(duixin.tieids));
		var res;
		getBangzhushowRequest.then(response => {
			res = response;
			console.log("帖子",res.data.data);
			if(res.data.code) {
				duixin.tiezineirong = res.data.data;
				duixin.jiazai = false;
				duixin.tiezijiazai = true;
			} else {
			  uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });
			}
		})
	},

    //给a标签添加跳转和复制链接事件
    wxParseTagATap: function (e) {
      var self = this;
      var href = e.currentTarget.dataset.src;
      //console.log(href);
      var domain = config.getDomain; //可以在这里进行一些路由处理

      if (href.indexOf(domain) == -1) {
        uni.setClipboardData({
          data: href,
          success: function (res) {
            uni.getClipboardData({
              success: function (res) {
                uni.showToast({
                  title: '链接已复制',
                  //icon: 'success',
                  image: "/static/images/uploads/link.png",
                  duration: 2000
                });
              }
            });
          }
        });
      } else {
        var slug = util.GetUrlFileName(href, domain);

        if (slug == 'index') {
          uni.switchTab({
            url: '../index/index'
          });
        } else {
          var getPostSlugRequest = wxRequest.getRequest(Api.getPostBySlug(slug));
        }
      }
    },
	
    //获取评论
    fetchCommentData: function () {
      
    },
	// 登录校验
	checkLogin() {
		// TODO 此处填写登录校验逻辑
		var userInfo = uni.getStorageSync('userInfo');
		if (userInfo) {
			return true;
		} else {
			uni.showModal({
				title: '提示',
				content: '请先登录',
				confirmText: '前往登录',
				success: function(res) {
					if (res.confirm) {
						
						uni.redirectTo({
							url: '/pages/login/login'
						});
					}
				}
			});
			return false;
		}
	},
	
	
	
	//获取当前页面
	getDangqianurl() {
		//获取当前页面栈的实例
		let pages = getCurrentPages();
		//获取当前页面
		let currentPage = pages[pages.length-1].$page.fullPath;
		let url = currentPage;
		uni.setStorageSync('dangqianUrl', url);
	},

	checkboxChange(n) {
		this.jubaoxuanzedata = n;
	},
	//点赞评论
	like(){
		
	},
	//删除评论
	del(){
		
	}
  }
};
</script>
<style>
@import "../tiezi/tiezi.css";
/* #ifdef H5 */
::v-deep img {
    max-width: 100%;
	border-radius: 10px;
}
::v-deep p {
	    display: block;
	    margin-top: 5px;
		margin-bottom:5px;
		line-height:30px !important;
		font-size: 18px;
} 
::v-deep pre {
	padding: 10px;
	background-color: #262626;
	border-radius: 10px;
	color: #eaeaea;
}
/* #endif */

</style>